package com.javabasic.algorithm.alibaba;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/3/27 9:07
 * @Version 1.0
 **/
public class 字符串变换 {
    static Scanner cin = new java.util.Scanner(System.in);

    static int[][] dp;
    public static void main(String[] args) {
        String s = cin.next();
        String t = cin.next();

//        String s = "acdk";
//        String t = "ckad";

        int len = t.length();
        dp = new int[len+1][len+1];
        HashMap<Character, Integer> mapS = new HashMap<>();
        HashMap<Character, Integer> mapT = new HashMap<>();
        Character chS, chT;
        for (int i = 0; i < len; i++) {
            chS = s.charAt(i);
            chT = t.charAt(i);
            if (!mapS.containsKey(chS)) {
                mapS.put(chS,1);
            } else {
                mapS.put(chS,mapS.get(chS)+1);
            }
            if (!mapT.containsKey(chT)) {
                mapT.put(chT,1);
            } else {
                mapT.put(chT,mapT.get(chT)+1);
            }
        }
        Set<Character> characters = mapS.keySet();
        if (characters.size() != mapT.keySet().size()) {
            System.out.println("-1");
            return;
        }
        for (Character character:characters) {
            if (mapS.get(character) != mapT.getOrDefault(character,-1)) {
                System.out.println("-1");
                return;
            }
        }
        boolean flag = false;
        for (int i = 1; i < len; i++) {
            System.out.println(t.substring(0,i+1));
            if (getMax(s,t.substring(0,i+1)) != i+1) {
                System.out.println(len - i);
                return;
            }else {
                flag = true;
            }
        }
        if (flag) {
            System.out.println("1");
        }

    }

    public static int getMax(String s, String t) {
        int lenS = s.length();
        int lenT = t.length();
        int MaxLen = -1;
        for (int i =0 ; i < lenS; i++) {
            for (int j = 0; j < lenT; j++) {
                if (s.charAt(i) == t.charAt(j)) {
                    dp[i+1][j+1] = dp[i][j]+1;
                } else {
                    dp[i+1][j+1] = Math.max(dp[i][j+1],dp[i+1][j]);
                }
                if (dp[i+1][j+1] > MaxLen) {
                    MaxLen = dp[i+1][j+1];
                }
            }
        }
        return MaxLen;
    }
}
